package Test;

import java.net.BindException;

public class Test10_KaoBeiShuZu {
    public static void main(String[] args) {
        //定义一个方法copyOfRange(int[] arr,int from,int to)
        //将数组arr从索引from（包含from）开始。
        //到索引to结束（不包含to）的元素复制到新数组中，将新数组返回。

        //分析：
        //1.定义原始数组arr1
        int [] arr1 = {1,2,3,4,5,6,7,8,9,10};
        int [] arr2 = copyOfRange(arr1,3,7);

        for (int i = 0; i < arr2.length; i++) {
            System.out.print(arr2[i] + " ");
        }
    }
    //2.提取arr1中元素插入给arr2（动态初始化）
    public static int[] copyOfRange(int[] arr,int from,int to) {
        //1)定义arr2
        int [] arr2 = new int[to - from];

        //2)将arr1赋值给arr1
        int index = 0;
        //伪造索引思想
        for (int i = from; i < to; i++) {
            arr2[index] = arr[i];
            index++;
        }
        return arr2;
    }
}
